package combofs.custom;

import com.google.common.io.Files;
import keter.combofs.api.ComboFs;
import keter.combofs.model.ComboFile;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * 可定制的模块样例
 */
@SpringBootApplication
public class CustomApp implements CommandLineRunner {

    private static final Logger logger = LoggerFactory.getLogger(CustomApp.class);

    @Autowired
    private ComboFs fs;

    @Override
    public void run(String... args) throws Exception {
        // 测试用的本地文件
        String testFileUri = "e:/temp/test.xml";
        java.io.File f = new java.io.File(testFileUri);
        // 保存文件：只保存文件流
        ComboFile file = fs.save(Files.toByteArray(f));
        logger.info("读取文件: uri={}",fs.getComboFile(file.getId()).getUri());
    }

    public static void main(String[] args) {
        SpringApplication.run(CustomApp.class, args);
    }

}
